package com.example.demo;

import com.example.demo.handler.LoginProxy;
import com.example.demo.handler.UploadProxy;
import org.springframework.boot.ExitCodeGenerator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import xyz.erupt.core.annotation.EruptAttachmentUpload;
import xyz.erupt.core.annotation.EruptScan;
import xyz.erupt.monitor.vo.Sys;
import xyz.erupt.upms.fun.EruptLogin;

import java.awt.*;
import java.net.URI;

@EruptLogin(value = LoginProxy.class)
@EruptAttachmentUpload(value = UploadProxy.class)
@SpringBootApplication
@EntityScan
@EruptScan
public class ExampleApplication extends SpringBootServletInitializer {

    private static String[] args;

    private static ConfigurableApplicationContext context;

    //详细使用方法详见项目内 README.md 文件说明
    public static void main(String[] args) {
        ExampleApplication.args=args;
        context = SpringApplication.run(ExampleApplication.class, args);
        try {
            System.setProperty("java.awt.headless", "false");
            Desktop.getDesktop().browse(new URI("http://localhost:8080"));
        } catch (Exception ignore) {
        }
        System.err.println("详细使用方法，请阅读：README.md");
    }

    //打WAR包的配置
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(ExampleApplication.class);
    }

    //重启项目
    public static void stop() {
        int exit = SpringApplication.exit(context, new ExitCodeGenerator() {
            @Override
            public int getExitCode() {
                return 0;
            }
        });
        System.exit(exit);
    }
}
